<?php
/**
 * MyFormModel class file
 */


/**
 * Extended CFormModel class
 * 
 * Supplies additional methods for form handling
 * 
 * @uses CFormModel
 * @package 
 * @version $Id: MyFormModel.php 3 2011-08-31 07:46:15Z juppwerner@googlemail.com $
 * @copyright 2010 Adam OPEL GmbH
 * @author Joachim Werner <joachim.pt.werner@de.gm.com> 
 * @license (tbd)
 */
class MyFormModel extends CFormModel
{
    // {{{ *** Members ***
    public $dateFields = '';

    // {{{ datesToLocale
    /**
     * Prepares all date attributes to the user locale
     * 
     * @access public
     * @return void
     */
    public function datesToLocale()
    {
        if($this->dateFields=='')
            return;
        foreach(explode(';',$this->dateFields) as $columnName) {
            if($this->$columnName=='') continue;
	    list($year,$month,$day) = explode( '-', $this->$columnName );
            $this->$columnName = Yii::app()->dateFormatter->formatDateTime( 
                mktime(0,0,0,$month,$day,$year),'medium',null
            );
        }
    } // }}} 
    // {{{ datesToISO
    /**
     * Prepares all date attributes to the ISO date format
     * 
     * @access public
     * @return void
     */
    public function datesToISO()
    {
        $dateFormat = CLocale::getInstance(Yii::app()->language)->getDateFormat('medium');
        if($this->dateFields=='')
            return;
        foreach( explode(';',$this->dateFields) as $columnName ) {
            if( $this->$columnName=='' ) {
                $this->$columnName='0000-00-00';
            } else {
                $this->$columnName = date("Y-m-d", CDateTimeParser::parse( $this->$columnName, $dateFormat ));
            }
        }
    } // }}} 
}
/* vim:set ai sw=4 sts=4 et fdm=marker fdc=4: */ 
?>
